package com.vone.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则校验
 * 
 * @author admin
 *
 */
public class RegularExpressionUtil {

	public static void main(String[] args) {
		System.out.println(checkDateyHHmmss("23:03:59"));
	}

	/**
	 * 日期格式HH:mm:ss
	 * 
	 * @param str
	 * @return
	 */
	public static boolean checkDateyHHmmss(String str) {
		String regExp = "^(?:[01]\\d|2[0-3])(?::[0-5]\\d){2}$";
		Pattern p = Pattern.compile(regExp);
		Matcher m = p.matcher(str);
		return m.find();
	}

	/**
	 * 日期格式yyyy-MM-dd HH:mm:ss
	 * 
	 * @param str
	 * @return
	 */
	public static boolean checkDateyyyyMMddHHmmss(String str) {
		String regExp = "^((((1[6-9]|[2-9]\\d)\\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\\d|3[01]))|(((1[6-9]|[2-9]\\d)\\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\\d|30))|(((1[6-9]|[2-9]\\d)\\d{2})-0?2-(0?[1-9]|1\\d|2[0-8]))|(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (?:[01]\\d|2[0-3])(?::[0-5]\\d){2}$";
		Pattern p = Pattern.compile(regExp);
		Matcher m = p.matcher(str);
		return m.find();
	}

	/**
	 * 日期格式yyyy-MM-dd
	 * 
	 * @param str
	 * @return
	 */
	public static boolean checkDateyyyymmdd(String str) {
		String regExp = "^((((1[6-9]|[2-9]\\d)\\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\\d|3[01]))|(((1[6-9]|[2-9]\\d)\\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\\d|30))|(((1[6-9]|[2-9]\\d)\\d{2})-0?2-(0?[1-9]|1\\d|2[0-8]))|(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$";
		Pattern p = Pattern.compile(regExp);
		Matcher m = p.matcher(str);
		return m.find();
	}

	/**
	 * 纯数字
	 * 
	 * @param str
	 * @return
	 */
	public static boolean checkNumber(String str) {
		String regExp = "^[0-9]*$";
		Pattern p = Pattern.compile(regExp);
		Matcher m = p.matcher(str);
		return m.find();
	}

	/**
	 * qq号码验证5到11位
	 * 
	 * @param str
	 * @return
	 */
	public static boolean checkQq(String str) {
		String regExp = "^\\d{5,11}$";
		Pattern p = Pattern.compile(regExp);
		Matcher m = p.matcher(str);
		return m.find();
	}

	/**
	 * 大写字母，小写字母，数字
	 * 
	 * @param str
	 * @return
	 */
	public static boolean checkLetterNumber(String str) {
		String regExp = "^[A-Za-z0-9]+$";
		Pattern p = Pattern.compile(regExp);
		Matcher m = p.matcher(str);
		return m.find();
	}

	/**
	 * 会员编号，匹配不包含4的数字，字数无线
	 * 
	 * @param str
	 * @return
	 */
	public static boolean checkMemberCodeUnlimited(String str) {
		String regExp = "^[012356789]*$";
		Pattern p = Pattern.compile(regExp);
		Matcher m = p.matcher(str);
		return m.find();
	}

	/**
	 * 会员编号，匹配不包含4的数字限制5位
	 * 
	 * @param str
	 * @return
	 */
	public static boolean checkMemberCodeFive(String str) {
		String regExp = "^[012356789]{5}$";
		Pattern p = Pattern.compile(regExp);
		Matcher m = p.matcher(str);
		return m.find();
	}

	/**
	 * 检查手机号码
	 * 
	 * @param str
	 * @return
	 */
	public static boolean checkCellphoneNumber(String str) {
		String regExp = "^[1]([3][0-9]{1}|59|58|88|89)[0-9]{8}$";
		Pattern p = Pattern.compile(regExp);
		Matcher m = p.matcher(str);
		return m.find();
	}

	/**
	 * 检查电子邮箱
	 * 
	 * @param str
	 * @return
	 */
	public static boolean checkEmail(String str) {
		String regExp = "^(\\w)+(\\.\\w+)*@(\\w)+((\\.\\w+)+)$";
		Pattern p = Pattern.compile(regExp);
		Matcher m = p.matcher(str);
		return m.find();
	}
}
